

import {
  legacy_createStore,
  applyMiddleware
} from 'redux'
import logger from 'redux-logger'
import thunk from 'redux-thunk'


import { ALLSIST, GETLIST, ALLCTTION,SETLUST,SETLISTTO } from '../types/store.d'

const initialState = {
  list: [],
  childrenList: [],
  tablist:[]
}
// 这里漂红  是因为状态数据增加或者减少了  没有将数据手动改变  []
const reducse = (state: ALLSIST = initialState, { type, payload }: ALLCTTION) => {
  switch (type) {

    case GETLIST:
      state.list = payload
      return { ...state }

    case SETLISTTO:
      state.tablist=payload;
      state.childrenList = payload[0].children
      return { ...state }

    case SETLUST:
     
      state.childrenList = state.tablist[payload].children
      
      return { ...state }

    default:
      return state
  }
}

const reaso = legacy_createStore(reducse, applyMiddleware(logger, thunk))

export default reaso

